package cn.ekuma.epos.datalogic.define.dao;

import cn.ekuma.data.dao.ModifiedLogDAO;
import cn.ekuma.epos.db.table.I_LocationLayout;

import com.openbravo.bean.Location;
import com.openbravo.bean.LocationLayout;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;

public class LocationLayoutDAO extends ModifiedLogDAO<LocationLayout>{

	public LocationLayoutDAO(I_Session s) {
		super(s);
	}

	@Override
	public TableDefinition getTable() {
		return new TableDefinition(s,
                "LOCATION_LAYOUT",
                 new Field[]{
                     new Field(I_LocationLayout.ID,Datas.STRING, Formats.STRING),
                     new Field(I_LocationLayout.NAME,Datas.STRING, Formats.STRING),
                     new Field(I_LocationLayout.LOCATIONID,Datas.STRING, Formats.STRING,Location.class),
                     new Field(I_LocationLayout.PARENTID,Datas.STRING, Formats.STRING,LocationLayout.class),
                     new Field(I_LocationLayout.MININUM,Datas.STRING, Formats.STRING),
                     new Field(I_LocationLayout.LASTMODIFIED,Datas.TIMESTAMP, Formats.TIMESTAMP),
                     new Field(I_LocationLayout.ISHOT,Datas.BOOLEAN, Formats.BOOLEAN)
                  },
                new int[]{0});
	}

	@Override
	public void writeInsertValues(DataWrite dp, LocationLayout obj)
			throws BasicException {
		dp.setString(1,obj.getKey());
		dp.setString(2,obj.getName());
		dp.setString(3,obj.getLocationId());
		dp.setString(4,obj.getM_sParentID());
		dp.setString(5,obj.getMiniNum());
		dp.setTimestamp(6, obj.getLastModified());
		dp.setBoolean(7,obj.isHot());
	}

	@Override
	public Class getSuportClass() {
		return LocationLayout.class;
	}

	@Override
	public LocationLayout readValues(DataRead dr, LocationLayout obj)
			throws BasicException {
		if(obj==null)
			obj=new LocationLayout();
		obj.setID(dr.getString(1));
		obj.setName(dr.getString(2));
		obj.setLocationId(dr.getString(3));
		obj.setM_sParentID(dr.getString(4));
		obj.setMiniNum(dr.getString(5));
		obj.setLastModified(dr.getTimestamp(6));
		obj.setHot(dr.getBoolean(7));
		return obj;
	}

}
